//
//  YWCell.m
//  网易新闻
//
//  Created by Yeewii@hotmail.com on 16/6/14.
//  Copyright © 2016年 Yeewii@hotmail.com. All rights reserved.
//

#import "YWCell.h"
#import <UIImageView+WebCache.h>
@implementation YWCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        [self setUpViews];
        
        [self setLayoutSubViews];
    }
    return self;
}

-(void)setUpViews
{
    
    _bgImage                       = [UIImageView new];
    [self.contentView addSubview:_bgImage];

    _titleLabel                    = [UILabel new];
    _titleLabel.font               = [UIFont systemFontOfSize:14];
    _titleLabel.numberOfLines      = 0;
    [self.contentView addSubview:_titleLabel];

    _sourceLabel                   = [UILabel new];
    _sourceLabel.font              = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:_sourceLabel];

    _replyCountLabel               = [UILabel new];
    _replyCountLabel.textAlignment = NSTextAlignmentRight;
    [self.contentView addSubview:_replyCountLabel];
    
}

-(void)setLayoutSubViews
{
    _bgImage.sd_layout
    .leftSpaceToView(self.contentView,10)
    .topSpaceToView(self.contentView,10)
//    .bottomSpaceToView(self.contentView,10)
    .widthIs(100)
    .autoHeightRatio(0.6);
    
    _titleLabel.sd_layout
    .topEqualToView(_bgImage)
    .leftSpaceToView(_bgImage,10)
    .rightSpaceToView(self.contentView,20)
//    .bottomEqualToView(_bgImage);这里坑死我了
    .maxHeightIs(90)
    .autoHeightRatio(0);
    
    _sourceLabel.sd_layout
    .leftEqualToView(_titleLabel)
    .bottomEqualToView(_bgImage)
    .heightIs(20)
    .autoHeightRatio(0);
    
    
    _replyCountLabel.sd_layout
    .rightSpaceToView(self.contentView,10)
    .bottomEqualToView(_bgImage)
    .heightIs(20);
    
    
    
    [self setupAutoHeightWithBottomView:_bgImage bottomMargin:10];
}




-(void)setUpSubViews:(id)subView :(Class)viewType
{
    //断言掉非view子类
    NSAssert([viewType isSubclassOfClass:[UIView class]], @"请设置UIView的子类");
    subView = [viewType new];
    [self.contentView addSubview:subView];
    NSLog(@"%@",NSStringFromClass([subView class]));

}


#pragma mark - setModel -
-(void)setModelData:(YWDataT1348647909107 *)modelData
{
    _modelData = modelData;
    [_bgImage sd_setImageWithURL:[NSURL URLWithString:_modelData.imgsrc]];
    _titleLabel.text = _modelData.title;
    _sourceLabel.text = _modelData.source;
    _replyCountLabel.text = [NSString stringWithFormat:@"%.f跟帖",_modelData.replyCount];
}


@end
